package top.buluoluo.ordersservice.utils;

import java.util.Map;
/**
 * 订单帮助类,主要解决类型为Map的参数的参数验证问题
 */
public class OrderHelper {

    // 验证配送地址
    public static void validateDeliveryAddress(Map<String, String> address) {
        requireKey(address, "recipientName");
        requireKey(address, "phone");
        requireKey(address, "province");
        requireKey(address, "city");
        requireKey(address, "detailAddress");
    }

    // 验证发票信息
    public static void validateInvoiceInfo(Map<String, String> invoice) {
        requireKey(invoice, "type");
        requireKey(invoice, "title");

        if ("COMPANY".equals(invoice.get("type"))) {
            requireKey(invoice, "taxNumber");
        }
    }

    private static void requireKey(Map<String, String> map, String key) {
        if (map == null || !map.containsKey(key) || map.get(key).isBlank()) {
            throw new IllegalArgumentException("缺少必要字段: " + key);
        }
    }
}